<div id="products"><!--start products-->
    
<?php
if(isset ($articles) == TRUE && count($articles) > 0) :
?>
    <div class="box">
        <div class="box_left">
            <div class="box_right"><a href="#" title="">Tin tức</a></div>
        </div>
    </div>
    <div class="article">
        
        <div>
            <form id="form-filter" method="post">
                <p>
                    <label>Xem theo danh mục:</label>
                    <select name="category">
                        <option value="">Chọn danh mục</option>
                        <?php if($category && $category->getNode()->getChildren()): ?>
                            <?php foreach($category->getNode()->getChildren() as $child): ?>
                            <option value="<?php echo Route::url('news-category',array('id' => $child->id, 'slug' => $child->slug)) ?>"><?php echo $child->name ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>

                    <label>Sắp xếp:</label>
                    <select name="order">
                        <option value="desc" <?php if(Session::instance()->get('order','desc') == 'desc'){ echo 'selected';} ?>>Gần đây</option>
                        <option value="asc" <?php if(Session::instance()->get('order','desc') == 'asc'){ echo 'selected';} ?>>Cũ nhất</option>
                    </select>
                </p>
            </form>
            
        </div>
        
        <ul class="others">
<?php
    foreach($articles as $obj) :
        preg_match('/<\s*img [^\>]*src\s*=\s*(["\'])(.*?)\1/', $obj->content, $matches);
        if (is_array($matches) && !empty($matches))
        {
           $image = $matches[2];
        }
        else
        {
           $image = Url::site('assets/client/images/no-image.jpg');
        }
?>
            <li>
                <p class="img">
                    <span>
                        <img src="<?php echo $image ?>" alt="" width="100" height="100" />
                    </span>
                </p>
                <p class="title">
                    <a href="<?php echo Route::url($route,array('id' => $obj->id,'slug' => $obj->slug)); ?>"><?php echo $obj->title ?></a>
                    <span>(26/05)</span>
                    <br />
                    <?php echo $obj->summary ?>
                </p>
            </li>
<?php
    endforeach;
?>
        </ul>
        
        <?php echo $pagination->display(); ?>
        <div class="clear"></div>
    </div>
    
<?php
else:
?>  
    <div id="bg_products">
        <p>Không tìm thấy bài viết nào</p>
    </div>
    
<?php endif; ?>
    
</div><!--end products-->
<script type="text/javascript">
    $(document).ready(function(){
        $('select[name="category"]').bind('change',function(){
            window.location.href = $(this).val();
        });

        $('select[name="order"]').bind('change',function(){
            $("#form-filter").trigger('submit');
        });
    });
</script>    
